package jp.ne.iforce.android.wifioffload;

import static jp.ne.iforce.android.wifioffload.BarCodeActivity.TAG;
import jp.ne.iforce.android.wifioffload.R;
import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.google.zxing.Result;

public class ResultDialog extends Dialog implements
		android.view.View.OnClickListener {

	private TextView mNumTextView;
	private TextView mFormatTextView;
	private Button mAccessBtn;
	private Button mCancelBtn;
	private BarCodeActivity barCodeActivity;

	public ResultDialog(Context context) {
		super(context);
		barCodeActivity = (BarCodeActivity) context;

		setContentView(R.layout.result_dialog);

		mFormatTextView = (TextView) findViewById(R.id.format_txt);
		mNumTextView = (TextView) findViewById(R.id.num_txt);
		mCancelBtn = (Button) findViewById(R.id.cancel_btn);
		mCancelBtn.setOnClickListener(this);
		mAccessBtn = (Button) findViewById(R.id.access_btn);
		mAccessBtn.setOnClickListener(this);

		setTitle(R.string.result_title);
	}

	void set(Result result) {
		Log.i(TAG, "set");
		String format = result.getBarcodeFormat().toString();
		result_text = result.getText();

		mNumTextView.setText(result_text);
		mFormatTextView.setText("FORMAT: " + format);
	}

	private String result_text;

	public void onClick(View v) {
		if (v == mAccessBtn) {
			barCodeActivity.setAps(result_text);
			barCodeActivity.getProfile();
			dismiss();
		} else if (v == mCancelBtn) {
			// オートフォーカス開始 / バーコード解析開始
			barCodeActivity.requestAutoFocus();
			dismiss();
		}
	}

}
